package com.fla.puzzle.ui.game;

import java.io.Serializable;

/**
 * Describes game field.
 * 
 * <p>
 * Contains position of the field in {@link GameModel}
 * </p>
 * 
 */
public class GameField implements Serializable {
    private static final long serialVersionUID = 1905821801423292982L;
    
    public int x;
    public int y;

    public GameField() {
    }

    public GameField(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public GameField(GameField src) {
        this.x = src.x;
        this.y = src.y;
    }

    /**
     * Set the point's x and y coordinates
     */
    public void set(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * Negate the point's coordinates
     */
    public final void negate() {
        x = -x;
        y = -y;
    }

    /**
     * Offset the point's coordinates by dx, dy
     */
    public final void offset(int dx, int dy) {
        x += dx;
        y += dy;
    }

    /**
     * Returns true if the point's coordinates equal (x,y)
     */
    public final boolean equals(int x, int y) {
        return this.x == x && this.y == y;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof GameField) {
            GameField p = (GameField) o;
            return this.x == p.x && this.y == p.y;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return x * 32713 + y;
    }

    @Override
    public String toString() {
        return "GameField(" + x + ", " + y + ")";
    }

}
